home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17246 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  46 lines

  1. Newsgroups: comp.lang.c,comp.lang.c++
  2. Path: newsfeed.internetmci.com!miwok!linex1!news
  3. From: mfried@linex.com (Marty Fried)
  4. Subject: Re: sizeof() question >>> :)
  5. X-Nntp-Posting-Host: sp12.linex.com
  6. Message-ID: <31714828.1574068@news.linex.com>
  7. Sender: news@linex1.linex.com
  8. Organization: Cirrius Cybernetics Corp
  9. X-Newsreader: Forte Agent .99e/32.209
  10. References: <1996Apr12.061927@topaz>
  11. Date: Sun, 14 Apr 1996 18:51:28 GMT
  12.  
  13. Once upon a time (OK, it was 12 Apr 96 06:19:27 +1000),
  14. naderr@topaz.cqu.edu.au wrote:
  15.  
  16. >Hi,
  17. >
  18. >How can I get, with a pointer,  the sizeof  of an  array that is
  19. >pointed by the pointer ?  (No it's not a tounge twister :)
  20. >
  21. >  while (!done) {
  22. >    ch = getchar();
  23. >    if (cp - *ct < sizeof(XXXXXXX)-1) {
  24. >      *cp++ = ch;
  25. >    } else {
  26. >      beep();
  27. >    }  
  28. >  }
  29.  
  30. You can't do it.  The only thing you could do is to use exception
  31. handling, and copy the characters within a try block until you get
  32. an exception.  I'm not sure if even that will give you the exact size
  33. or work all the time, although it will prevent an exception from
  34. causing the program to crash.
  35.  
  36. I suppose you could also create a pointer class which contains the
  37. size and pointer as members, and pass the class rather than the
  38. pointer.
  39.  
  40. cc: naderr@topaz.cqu.edu.au
  41.  
  42. _______________________________________________________
  43. Marty Fried - mfried@linex.com     Press Enter to Exit
  44. San Anselmo, CA                           -NT message
  45. (MSVC4 + MFC) && (Win95 || NT);             
  46.